from jqdatasdk import *
# from jqdata import *
from jq_utils import *
import datetime
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
pd.reset_option('display.float_format')

sdk_auth()

def pdate(dstr):
    return datetime.datetime.strptime(dstr, '%Y-%m-%d').date()

def get_index_codes(codes = "000300.XSHG"):
    ret = []
    if type(codes) == list:
        for code in codes:
            ret += get_index_stocks(code, date=None)
    else:
        ret = get_index_stocks(codes)
    return ret

zz800 = get_index_codes([ "000905.XSHG", "000300.XSHG"])
latest_trade_days = get_trade_days(count = 10)

#name=finance.run_query(query(finance.FUND_MAIN_INFO).filter(finance.FUND_MAIN_INFO.main_code==code)).name
#print(name[0]) # 基金名称
#    q=query(finance.FUND_PORTFOLIO_STOCK.code ,# 	基金代码	varchar(12)
#            finance.FUND_PORTFOLIO_STOCK.period_start ,# 	开始日期	date
#    #         finance.FUND_PORTFOLIO_STOCK.period_end ,# 	报告期	date
#            finance.FUND_PORTFOLIO_STOCK.pub_date ,# 	公告日期	date
#    #         finance.FUND_PORTFOLIO_STOCK.report_type_id ,# 	报告类型编码	int
#    #         finance.FUND_PORTFOLIO_STOCK.report_type ,# 	报告类型	varchar(32)
#            finance.FUND_PORTFOLIO_STOCK.rank ,# 	持仓排名	int
#            finance.FUND_PORTFOLIO_STOCK.symbol ,# 	股票代码	varchar(32)
#            finance.FUND_PORTFOLIO_STOCK.name ,# 	股票名称	varchar(100)
#    #         finance.FUND_PORTFOLIO_STOCK.shares ,# 	持有股票	decimal(20,4)
#    #         finance.FUND_PORTFOLIO_STOCK.market_cap ,# 	持有股票的市值	decimal(20,4)
#            finance.FUND_PORTFOLIO_STOCK.proportion # 	占净值比例	decimal(10,4)
#
#           ).filter(finance.FUND_PORTFOLIO_STOCK.code==code
#                   ).order_by(finance.FUND_PORTFOLIO_STOCK.period_start.desc(), # 开始日期降序
#                              finance.FUND_PORTFOLIO_STOCK.rank.asc() # 持仓排名升序
#                             ).limit(100)
#    df=finance.run_query(q)
